<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Mr_saudara extends CI_Controller {

	function __construct() {
        parent::__construct();
        $this->isLogin();	
		$this->load->model("master/master_saudara"); 	
	}
	
	function isLogin(){
		$login=$this->session->userdata('isLogin');
		if(! isset($login)||$login != true){
			$this->session->set_flashdata('error_login', 'Untuk Mengakses Admin Anda Harus Login!');
			redirect('login');	
		}
	}
	
	function add_exe()
	{
		$tgl = $this->input->post('tgl_lahir');
		$tglMySQL = date("Y-m-d", strtotime ($tgl));
		
		$dataInsert = array(
			'nis' => $this->input->post('nis'),
			'hubungan' => $this->input->post('hubungan'),
			'nama' => $this->input->post('nama'),
			'jk' => $this->input->post('jk'),
			'tgl_lahir' => $tglMySQL,
			'nm_sekolah' => $this->input->post('nm_sekolah'),
			'kelas' => $this->input->post('kelas')
		);
		$this->master_saudara->add($dataInsert);		
		$back = htmlspecialchars($_SERVER['HTTP_REFERER']);
		redirect ($back);
	}	
	
	function edit()
	{
		$id_mr_saudara = $this->input->post('id_mr_saudara');
		$data['list']=$this->master_saudara->edit($id_mr_saudara);	
		$this->load->view('master/mr_saudara/edit',$data);
	}
	
	function update()
	{
		$id_mr_saudara=$this->input->post('id_mr_saudara');
		
		$tgl = $this->input->post('tgl_lahir');
		$tglMySQL = date("Y-m-d", strtotime ($tgl));
		
		$dataUpdate = array(
			'hubungan' => $this->input->post('hubungan'),
			'nama' => $this->input->post('nama'),
			'jk' => $this->input->post('jk'),
			'tgl_lahir' => $tglMySQL,
			'nm_sekolah' => $this->input->post('nm_sekolah'),
			'kelas' => $this->input->post('kelas')
		);
		$this->master_saudara->update($id_mr_saudara,$dataUpdate);
		$back = htmlspecialchars($_SERVER['HTTP_REFERER']);
		redirect ($back);
	}	
	
	function delete()
	{
		$id_mr_saudara = $this->security->xss_clean($this->uri->segment(3));
		$this->master_saudara->delete($id_mr_saudara);
		$back = htmlspecialchars($_SERVER['HTTP_REFERER']);
		redirect ($back);
	}

}